package com.woparker.kiosk.bean;

import java.io.Serializable;

public class SlotDTO implements Serializable {
    private static final long serialVersionUID = 4L;
    /** 场地id */
    private long placeId;
    /** 车位号 */
    private String name;
    /** 车库 */
    private String garage;
    /** 区域 */
    private String area;
    /** 泊车时间 */
    private long date;
    /** 车牌号 */
    private String plate;
    /** 车牌颜色 */
    private String plateColor;
    /** 照片 */
    private String pic;
    /** X坐标 */
    private int x;
    /** Y坐标 */
    private int y;
    /** 楼层名 */
    private String placeName;
    /** 更新时间 */
    private long updateDate;

    public SlotDTO() {

    }

    public SlotDTO(long placeId, String name, String garage, String area, long date,
                   String plate, String plateColor, String pic, int x, int y,String placeName) {
        super();
        this.placeId = placeId;
        this.name = name;
        this.garage = garage;
        this.area = area;
        this.date = date;
        this.plate = plate;
        this.plateColor = plateColor;
        this.pic = pic;
        this.x = x;
        this.y = y;
        this.placeName = placeName;
    }

    public long getPlaceId() {
        return placeId;
    }
    public void setPlaceId(long placeId) {
        this.placeId = placeId;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getGarage() {
        return garage;
    }
    public void setGarage(String garage) {
        this.garage = garage;
    }
    public String getArea() {
        return area;
    }
    public void setArea(String area) {
        this.area = area;
    }

    public long getDate() {
        return date;
    }

    public void setDate(long date) {
        this.date = date;
    }

    public String getPlate() {
        return plate;
    }
    public void setPlate(String plate) {
        this.plate = plate;
    }
    public String getPlateColor() {
        return plateColor;
    }
    public void setPlateColor(String plateColor) {
        this.plateColor = plateColor;
    }
    public String getPic() {
        return pic;
    }
    public void setPic(String pic) {
        this.pic = pic;
    }
    public int getX() {
        return x;
    }
    public void setX(int x) {
        this.x = x;
    }
    public int getY() {
        return y;
    }
    public void setY(int y) {
        this.y = y;
    }

    public String getPlaceName() {
        return placeName;
    }

    public void setPlaceName(String placeName) {
        this.placeName = placeName;
    }

    public long getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(long updateDate) {
        this.updateDate = updateDate;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof SlotDTO) {
            SlotDTO lotBean = (SlotDTO) obj;

            if (name != null && name.trim().length() > 0 && lotBean.getName() != null && lotBean.getName().trim().length() > 0 && name.equals(lotBean.getName())) {
                replace(this, lotBean);
                return true;
            }

            if (plate != null && plate.trim().length() > 0 && lotBean.getPlate() != null && lotBean.getPlate().trim().length() > 0 && plate.equals(lotBean.getPlate())) {
                replace(this, lotBean);
                return true;
            }
        }

        return false;
    }

    private void replace(SlotDTO lotBean1, SlotDTO lotBean2) {
        if (lotBean1.getPlateColor() == null || lotBean1.getPlateColor().trim().length() == 0) {
            lotBean1.setPlateColor(lotBean2.getPlateColor());
        }

        if (lotBean1.getPic() == null || lotBean1.getPic().trim().length() == 0) {
            lotBean1.setPic(lotBean2.getPic());
        }

        if (lotBean1.getDate() == 0) {
            lotBean1.setDate(lotBean2.getDate());
        }

        if (lotBean1.getUpdateDate() == 0) {
            lotBean1.setUpdateDate(lotBean2.getUpdateDate());
        }
    }

    @Override
    public int hashCode() {
        String result = "";
        if (name != null && name.trim().length() > 0) {
            result = name;
        } else if (plate != null && plate.trim().length() > 0) {
            result = plate;
        }
        return result.hashCode();
    }
}
